<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2014 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Tuolaji <479923197@qq.com>
// +----------------------------------------------------------------------
/**
 */
namespace Robot\Controller;
use Think\Controller;
class PublicController extends AdminbaseController {

    function _initialize() {}
    
    //后台登陆界面
    public function login() {
    	if(isset($_SESSION['ROBOT_ID'])){//已经登录
    		$this->success(L('LOGIN_SUCCESS'),U("Robot/Index/index"));
    	}else{
    		$this->display("./login");
    	}
    }
    
    public function logout(){
    	session('ROBOT_ID',null);
    	$this->redirect("public/login");
    }
    
    public function dologin(){
    	$name = I("post.username");
    	if(empty($name)){
    		$this->error('用户名不能为空');
    	}
    	$pass = I("post.password");
    	if(empty($pass)){
    		$this->error('密码不能为空');
    	}
    	$verify = I("post.verify");
    	if(empty($verify)){
    		$this->error('验证码不能为空');
    	}
    	//验证码
    	if(!sp_check_verify_code()){
    		$this->error('验证码错误');
    	}else{

            if($name != "qkt-robot"
                || $pass != "Qukaituan168") {
                $this->error('用户不存在');
            } else {

                $_SESSION["ROBOT_ID"]="Qkt1qazxsw2-123456";
                $_SESSION['name']="qkt-robot";

                setcookie("robot_username",$name,time()+100*30*24*3600,"/");
                $this->success('登陆成功',U("Index/index"));

            }

    	}
    }

}